package org.dtrd.modules.archive.entity.bean.report;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.dtrd.common.util.StringUtil;
import org.dtrd.config.system.Constant;
import org.dtrd.modules.archive.entity.po.DtrdEntRdArchiveLaboratory;

/**
 * <p>
 * 实验室检查
 * </p>
 *
 * @author QR
 * @since 2022-01-21
 */
@Getter
@Setter
@ApiModel(value = "实验室检查详情")
public class LaboratoryReport {

    // 血糖检测
    @ApiModelProperty("血糖检查日期")
    private String sugarCheckDate;
    @ApiModelProperty("空腹血糖")
    private String sugarFasting;
    @ApiModelProperty("随机血糖")
    private String sugarRandom;
    @ApiModelProperty("餐后2h血糖")
    private String sugarAfter2;
    @ApiModelProperty("HbA1c")
    private String hba1c;
    @ApiModelProperty("血糖报告")
    private String sugarReportPhoto;

    // ogtt 实验 + 胰岛功能
    @ApiModelProperty("OGTT2h血糖检查日期")
    private String ogttCheckDate;
    @ApiModelProperty("血糖空腹服糖前")
    private String sugarLimosis;
    @ApiModelProperty("血糖30min")
    private String sugar30min;
    @ApiModelProperty("血糖1h")
    private String sugar1h;
    @ApiModelProperty("血糖2h")
    private String sugar2h;
    @ApiModelProperty("血糖3h")
    private String sugar3h;
    @ApiModelProperty("血糖空腹服糖前")
    private Float sugarLimosisNo;
    @ApiModelProperty("血糖30min")
    private Float sugar30minNo;
    @ApiModelProperty("血糖1h")
    private Float sugar1hNo;
    @ApiModelProperty("血糖2h")
    private Float sugar2hNo;
    @ApiModelProperty("血糖3h")
    private Float sugar3hNo;
    @ApiModelProperty("胰岛素空腹")
    private String isletLimosis;
    @ApiModelProperty("胰岛素30min")
    private String islet30min;
    @ApiModelProperty("胰岛素1h")
    private String islet1h;
    @ApiModelProperty("胰岛素2h")
    private String islet2h;
    @ApiModelProperty("胰岛素3h")
    private String islet3h;
    @ApiModelProperty("胰岛素空腹")
    private Float isletLimosisNo;
    @ApiModelProperty("胰岛素30min")
    private Float islet30minNo;
    @ApiModelProperty("胰岛素1h")
    private Float islet1hNo;
    @ApiModelProperty("胰岛素2h")
    private Float islet2hNo;
    @ApiModelProperty("胰岛素3h")
    private Float islet3hNo;
    @ApiModelProperty("C肽空腹")
    private String peptideLimosis;
    @ApiModelProperty("C肽30min")
    private String peptide30min;
    @ApiModelProperty("C肽1h")
    private String peptide1h;
    @ApiModelProperty("C肽2h")
    private String peptide2h;
    @ApiModelProperty("C肽3h")
    private String peptide3h;
    @ApiModelProperty("C肽空腹")
    private Float peptideLimosisNo;
    @ApiModelProperty("C肽30min")
    private Float peptide30minNo;
    @ApiModelProperty("C肽1h")
    private Float peptide1hNo;
    @ApiModelProperty("C肽2h")
    private Float peptide2hNo;
    @ApiModelProperty("C肽3h")
    private Float peptide3hNo;
    @ApiModelProperty("oggt报告")
    private String oggtReportPhoto;

    // 血脂检测
    @ApiModelProperty("总胆固醇TC检查日期")
    private String bloodFatCheckDate;
    @ApiModelProperty("总胆固醇TC")
    private String tc = "——";
    @ApiModelProperty("甘油三酯TG")
    private String tg = "——";
    @ApiModelProperty("低密度脂蛋白LDL_C")
    private String ldlc = "——";
    @ApiModelProperty("高密度脂蛋白HDL_C")
    private String hdlc = "——";
    @ApiModelProperty("非高密度脂蛋白nonHDL_C")
    private String nonHdlc = "——";
    @ApiModelProperty("血脂报告")
    private String lipidReportPhoto;

    // 肝功能检查 liver Function Check
    @ApiModelProperty("谷丙转氨酶ALT检查日期")
    private String liverFunctionCheckDate;
    @ApiModelProperty("谷丙转氨酶ALT")
    private String alt = "——";
    @ApiModelProperty("谷草转氨酶AST")
    private String ast = "——";
    @ApiModelProperty("总胆红素T_BIL")
    private String tbil = "——";
    @ApiModelProperty("碱性磷酸酶ALP")
    private String alp = "——";
    @ApiModelProperty("肝功能检查报告")
    private String liverFunctionCheckReport;
    @ApiModelProperty("肝功能检查报告单")
    private String liverReportPhoto;

    // 肾功能检查 kidney Function Check
    @ApiModelProperty("尿常规_尿蛋白检查日期")
    private String kidneyFunctionCheckDate;
    @ApiModelProperty("尿常规_尿蛋白")
    private String urineProtein = "——";
    @ApiModelProperty("尿白蛋白UAE")
    private String uae = "——";
    @ApiModelProperty("24h尿白蛋白24hUAE")
    private String uae24 = "——";
    @ApiModelProperty("尿白蛋白尿肌酐ACR")
    private String acr = "——";
    @ApiModelProperty("血清肌酐Cr")
    private String cr = "——";
    @ApiModelProperty("尿素氮")
    private String ureaNitrogen = "——";
    @ApiModelProperty("肾小球滤过率GFR")
    private String gfr = "——";
    @ApiModelProperty("内生肌酐清除率")
    private String creatinineRate = "——";
    @ApiModelProperty("血尿酸")
    private String bua = "——";
    @ApiModelProperty("肾功能检查报告")
    private String kidneyReportPhoto;


    // 酮体检查
    @ApiModelProperty("尿酮体检查日期")
    private String ketoneCheckDate;
    @ApiModelProperty("血酮体")
    private String bloodKetone = "——";
    @ApiModelProperty("尿酮体")
    private String urineKetone = "——";
    @ApiModelProperty("酮体检查报告")
    private String ketoneReportPhoto;


    // 血气分析检查
    @ApiModelProperty("血气分析PH检查日期")
    private String phCheckDate;
    @ApiModelProperty("血气分析PH")
    private String ph = "——";
    @ApiModelProperty("血气分析HCO3")
    private String hco3 = "——";
    @ApiModelProperty("电解质Na+")
    private String na = "——";
    @ApiModelProperty("电解质K+")
    private String kei = "——";
    @ApiModelProperty("血浆渗透压")
    private String opp = "——";
    @ApiModelProperty("溃疡组织培养药敏试验")
    private String ulcerativeDrugSensitivity = "——";
    @ApiModelProperty("血气检查报告")
    private String bloodReportPhoto;

    public LaboratoryReport setNull() {
        // region 血糖检测
        sugarCheckDate = null;
        sugarFasting = null;
        sugarRandom = null;
        sugarAfter2 = null;
        hba1c = null;
        // endregion
        // region ogtt/胰岛功能
        ogttCheckDate = null;
        sugarLimosis = null;
        sugar30min = null;
        sugar1h = null;
        sugar2h = null;
        sugar3h = null;
        isletLimosis = null;
        islet30min = null;
        islet1h = null;
        islet2h = null;
        islet3h = null;
        peptideLimosis = null;
        peptide30min = null;
        peptide1h = null;
        peptide2h = null;
        peptide3h = null;
        // endregion
        return this;
    }

    public LaboratoryReport parseFromPO(DtrdEntRdArchiveLaboratory po) {
        // region 血糖检测
        if (po.getSugarFastingDate() != null) {
            sugarCheckDate = DateUtil.format(po.getSugarFastingDate(), DatePattern.NORM_DATE_PATTERN);
        }
        if (po.getSugarFasting() != null) {
            sugarFasting = po.getSugarFasting() + Constant.Unit.SUGAR_VALUE_UNIT;
        }
        if (po.getSugarRandom1() != null) {
            sugarRandom = po.getSugarRandom1() + Constant.Unit.SUGAR_VALUE_UNIT;
        }
        if (po.getSugarAfter2() != null) {
            sugarAfter2 = po.getSugarAfter2() + Constant.Unit.SUGAR_VALUE_UNIT;
        }
        if (po.getHba1c() != null) {
            hba1c = po.getHba1c() + "%";
        }
        // endregion
        // region 血脂检查
        if (po.getHdlcDate() != null) {
            bloodFatCheckDate = DateUtil.format(po.getHdlcDate(), DatePattern.NORM_DATE_PATTERN);
        }
        if (po.getTc() != null) {
            tc = po.getTc() + Constant.Unit.SUGAR_VALUE_UNIT;
        }
        if (po.getTg() != null) {
            tg = po.getTg() + Constant.Unit.SUGAR_VALUE_UNIT;
        }
        if (po.getLdlc() != null) {
            ldlc = po.getLdlc() + Constant.Unit.SUGAR_VALUE_UNIT;
        }
        if (po.getHdlc() != null) {
            hdlc = po.getHdlc() + Constant.Unit.SUGAR_VALUE_UNIT;
        }
        if (po.getNonHdlc() != null) {
            nonHdlc = po.getNonHdlc() + Constant.Unit.SUGAR_VALUE_UNIT;
        }
        // endregion
        // region 肝功能检查
        if (po.getAltDate() != null) {
            liverFunctionCheckDate = DateUtil.format(po.getAltDate(), DatePattern.NORM_DATE_PATTERN);
        }
        if (po.getAlt() != null) {
            alt = po.getAlt() + Constant.Unit.AMINOTRANSFERASE_UNIT;
        }
        if (po.getAst() != null) {
            ast = po.getAst() + Constant.Unit.AMINOTRANSFERASE_UNIT;
        }
        if (po.getTbil() != null) {
            tbil = po.getTbil() + Constant.Unit.UMOL_L;
        }
        if (po.getAlp() != null) {
            alp = po.getAlp() + Constant.Unit.AMINOTRANSFERASE_UNIT;
        }
        if (po.getPhoto() != null) {
            liverFunctionCheckReport = po.getPhoto();
        }
        // endregion
        // region 肾功能检查
        if (po.getUrineProteinDate() != null) {
            kidneyFunctionCheckDate = DateUtil.format(po.getUrineProteinDate(), DatePattern.NORM_DATE_PATTERN);
        }
        if (po.getUrineProtein() != null) {
            urineProtein = Constant.YinYang.valueOf(po.getUrineProtein()).getName();
        }
        if (po.getUae() != null) {
            uae = po.getUae() + "ug/min";
        }
        if (po.getUae24() != null) {
            uae24 = po.getUae24() + "mg/24h";
        }
        if (po.getAcr() != null) {
            acr = po.getAcr() + "mg/g";
        }
        if (po.getCr() != null) {
            cr = po.getCr() + "ummol/L";
        }
        if (po.getBua() != null) {
            bua = po.getBua() + "nmol/L";
        }
        if (po.getUreaNitrogen() != null) {
            ureaNitrogen = po.getUreaNitrogen() + Constant.Unit.MMOL_L;
        }
        gfr = wrapperValue(po.getGfr(), "%");
        creatinineRate = wrapperValue(po.getCreatinineRate(), "%");
        // endregion
        // region 酮体检查
        if (po.getUrineKetoneDate() != null) {
            ketoneCheckDate = DateUtil.format(po.getUrineProteinDate(), DatePattern.NORM_DATE_PATTERN);
        }
        if (po.getBloodKetone() != null) {
            bloodKetone = po.getBloodKetone() + "";
        }
        Integer urineKetoneType = po.getUrineKetone();
        if (urineKetoneType != null) {
            switch (urineKetoneType){
                case 1: urineKetone = "阴性";break;
                case 2: urineKetone = "弱阳性";break;
                case 3: urineKetone = "阳性";break;
                case 4: urineKetone = "强阳性";break;
            }

        }
        // endregion
        // region 血气分析检查
        if (po.getPhDate() != null) {
            phCheckDate = DateUtil.format(po.getPhDate(), DatePattern.NORM_DATE_PATTERN);
        }
        if (po.getPh() != null) {
            ph = po.getPh() + "";
        }
        if (po.getHco3() != null) {
            hco3 = po.getHco3() + "";
        }
        if (po.getNa() != null) {
            na = po.getNa() + "";
        }
        if (po.getKei() != null) {
            kei = po.getKei() + "";
        }
        if (po.getOpp() != null) {
            opp = po.getOpp() + "";
        }
        if (po.getUlcerativeDrugSensitivity() != null) {
            ulcerativeDrugSensitivity = po.getUlcerativeDrugSensitivity();
        }
        // endregion
        // region ogtt/胰岛功能
        if (po.getOgttPeptideDate() != null) {
            ogttCheckDate = DateUtil.format(po.getOgttPeptideDate(), DatePattern.NORM_DATE_PATTERN);
        }
        if (po.getSugarLimosis() != null) {
            sugarLimosis = po.getSugarLimosis() + Constant.Unit.SUGAR_VALUE_UNIT;
            sugarLimosisNo = po.getSugarLimosis();
        }
        if (po.getSugar30min() != null) {
            sugar30min = po.getSugar30min() + Constant.Unit.SUGAR_VALUE_UNIT;
            sugar30minNo = po.getSugar30min();
        }
        if (po.getSugar1h() != null) {
            sugar1h = po.getSugar1h() + Constant.Unit.SUGAR_VALUE_UNIT;
            sugar1hNo = po.getSugar1h();
        }
        if (po.getSugar2h() != null) {
            sugar2h = po.getSugar2h() + Constant.Unit.SUGAR_VALUE_UNIT;
            sugar2hNo = po.getSugar2h();
        }
        if (po.getSugar3h() != null) {
            sugar3h = po.getSugar3h() + Constant.Unit.SUGAR_VALUE_UNIT;
            sugar3hNo = po.getSugar3h();
        }
        if (po.getIsletLimosis() != null) {
            isletLimosis = po.getIsletLimosis() + Constant.Unit.INSULIN_UNIT;
            isletLimosisNo = po.getIsletLimosis();
        }
        if (po.getIslet30min() != null) {
            islet30min = po.getIslet30min() + Constant.Unit.INSULIN_UNIT;
            islet30minNo = po.getIslet30min();
        }
        if (po.getIslet1h() != null) {
            islet1h = po.getIslet1h() + Constant.Unit.INSULIN_UNIT;
            islet1hNo = po.getIslet1h();
        }
        if (po.getIslet2h() != null) {
            islet2h = po.getIslet2h() + Constant.Unit.INSULIN_UNIT;
            islet2hNo = po.getIslet2h();
        }
        if (po.getIslet3h() != null) {
            islet3h = po.getIslet3h() + Constant.Unit.INSULIN_UNIT;
            islet3hNo = po.getIslet3h();
        }
        if (po.getPeptideLimosis() != null) {
            peptideLimosis = po.getPeptideLimosis() + Constant.Unit.C_PEPTIDE_UNIT;
            peptideLimosisNo = po.getPeptideLimosis();
        }
        peptide30min = wrapperValue(po.getPeptide30min(), Constant.Unit.C_PEPTIDE_UNIT);
        peptide30minNo = po.getPeptide30min();
        peptide1h = wrapperValue(po.getPeptide1h(), Constant.Unit.C_PEPTIDE_UNIT);
        peptide1hNo = po.getPeptide1h();
        peptide2h = wrapperValue(po.getPeptide2h(), Constant.Unit.C_PEPTIDE_UNIT);
        peptide2hNo = po.getPeptide2h();
        peptide3h = wrapperValue(po.getPeptide3h(), Constant.Unit.C_PEPTIDE_UNIT);
        peptide3hNo = po.getPeptide3h();
        // endregion
        return this;
    }

    private String wrapperValue(Float value, String unit) {
        return value == null ? "——" : (value + unit);
    }

}
